<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content" style="padding:15px 20px 0px 20px;">
            <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                <div class="form-group">
                    <label class="control-label col-sm-1">柜号:</label>
                    <div class="col-sm-2">
                        <input type="text" id="createPlanNo" name="createPlanNo" class="form-control">
                    </div>
                    <label class="control-label col-sm-1">装柜地点:</label>
                    <div class="col-sm-2">
                        <input type="text" id="createPlanPlace" name="createPlanPlace" class="form-control">
                    </div>

                    <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                </div>
            </form>
        </div>
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                <button  class="report-btn layui-btn  layui-btn-sm"  style="margin-top: -6px;margin-left: -4px">
                    <i class="fa fa-check-square-o" aria-hidden="true"></i> 生成质检报告
                </button>
                <button  class="export-btn layui-btn  layui-btn-sm" style="margin-top: -6px;margin-left: -2px">
                    <i class="fa fa-download" aria-hidden="true"></i> 导出当前数据
                </button>

            </div>
            <!-- START 操作按钮 -->
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/quality/findByQuality.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>


<div id="layer_supplier_window" style="display: none;overflow-x: hidden;overflow-y: hidden">
    <!-- START 内容部分 -->
    <div class="container" >
        <form class="form-horizontal" id="info-supplier-form" method="post" autocomplete="off" style="margin: auto">
            <div class="form-group" style="margin-top: 20px">
                <label class="category control-label col-sm-2" style="max-width: 100px">供应商</label>
                <div class="col-sm-8" style="max-width: 300px;">
                    <select  id="productSupplierId" name="productSupplierId" xm-select="productSupplierId" xm-select-radio xm-select-search>
                        <%for(var dict in supplier){%>
                        <option value="${dict.id}">${dict.supplierName}</option>
                        <%}%>
                    </select>
                    <input type="hidden" name="supplierName" id="supplierName">
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">抽检数量</label>
                <div class="col-sm-8" style="max-width: 300px;">
                    <input type="text" id="qualityNumber" name="qualityNumber" class="form-control"  />
                </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-2" style="max-width: 100px">质检结果</label>
                    <div class="col-sm-8" style="max-width: 300px;">
                        <select  id="qualityResult" name="qualityResult" class="form-control" >
                            <option value="">请选择</option>
                            <option value="质检通过">质检通过</option>
                            <option value="质检未通过">质检未通过</option>
                            <option value="二次质检">二次质检</option>
                        </select>
                    </div>
            </div>
            <div class="form-group" style="margin-top: 20px">
                <label class="control-label col-sm-7" style="max-width: 100px"></label>
                <button type="button" class="save-produce-btn btn btn-primary">
                    <i class="fa fa-save"></i> 保存
                </button>
            </div>
        </form>
    </div>
    <!-- END 内容部分 -->
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,chosen,chosen-demo'}){}%>
<script>
    var $relatedTable = $('#relatedTable');
    $(function(){
        //START 表格配置
        $relatedTable.bootstrapTable({
            detailView: true,
            columns: [
                {
                    field: 'state',
                    checkbox: true,
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '装柜地点',
                    field: 'createPlanPlace',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '总件数',
                    field: 'createPlanTotal',
                    align: 'center',
                    valign: 'middle'
                },{
                    title: '龙舟船期',
                    field: 'createPlanBoatDate',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '状态',
                    field: 'createPlanStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        var result='';
                        switch (v) {
                            case 1:
                                result='未处理';
                                break;
                            case 2:
                                result='已分配';
                                break;
                            case 3:
                                result='已发运';
                                break;
                            case 4:
                                result='已开船';
                                break;
                            case 5:
                                result='已清关';
                                break;
                            case 6:
                                result='已送货';
                                break;
                            case 7:
                                result='已入库';
                                break;
                            default:
                                result='';
                        }
                        return result;
                    }
                },
                {
                    title: '质检状态',
                    field: 'createQualityStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        var result='';
                        switch (v) {
                            case 0:
                                result='未质检';
                                break;
                            case 1:
                                result='完成质检';
                                break;
                            case 2:
                                result='部分质检';
                                break;
                            default:
                                result='';
                        }
                        return result;
                    }
                }

            ],
            onLoadSuccess : function(){

            },onExpandRow: function (index, row, $detail) {
                InitSubTable(index, row, $detail);
            }
        });

        //初始化子表格(无线循环)
        function InitSubTable (index, row, $detail) {
            var parentId = row.id;
            var cur_table = $detail.html('<table id="disTable"></table>').find('table');
            $(cur_table).bootstrapTable({
                url: '/sea/physical/distribute/findByCreateId',
                method: 'get',
                clickToSelect: true,
                queryParams: { createId: parentId},
                ajaxOptions: { id: parentId },
                clickToSelect: true,
                //height: 500,
                detailView: false,//父子表
                uniqueId: "id",
                pageSize: 10,
                pageList: [10, 25],
                columns: [
                    {
                        field: 'createShipmentId',
                        title: 'ShipmentId'
                    },
                    {
                        field: 'createSku',
                        title: 'SKU'
                    },{
                        field: 'createFnSku',
                        title: 'FNSKU'
                    },{
                        field: 'productName',
                        title: '产品名称'
                    },{
                        field: 'productColorName',
                        title: '颜色'
                    },{
                        field: 'productCm',
                        title: '尺码(CM)'
                    },{
                        field: 'productInch',
                        title: '尺码(INCH)'
                    },{
                        field: 'createNumber',
                        title: '数量'
                    },{
                        field: 'createPackage',
                        title: '装箱量'
                    },{
                        field: 'createBoxNumber',
                        title: '箱数'
                    },{
                        field: 'createSupplierName',
                        title: '供应商'
                    },{
                        field: 'erpProducePo',
                        title: 'PO号'
                    },{
                        field: 'erpProducePrice',
                        title: '采购单价'
                    },{
                        field: 'createQualityStatus',
                        title: '质检状态',
                        formatter:function (v,r) {
                            var result='';
                            switch (v) {
                                case 0:
                                    result='未质检';
                                    break;
                                case 1:
                                    result='已质检';
                                    break;
                                default:
                                    result='';
                            }
                            return result;
                        }
                    }],
                onLoadSuccess : function(){
                    $('.edit-sku-btn').on('click',function(){
                        var id = $(this).attr('data-val');
                        layer.open({
                            type: 2,
                            area: ['500px','400px'],
                            content: ['/sea/physical/distribute/editPage.do?id='+id, 'yes']
                        });
                    });
                }
            });
        };
    });


    // 条件查询
    $('.search-btn').on('click',function () {
        $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/quality/findByQuality.do?'+$('#search-form').serialize() });
    });

    $('.report-btn').on('click',function () {
        var selDatas = $relatedTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            layer.open({
                type:1,
                title:'生成质检单',
                area:['550px','370px'],
                skin:'layui-layer-lan',//layui-layer-molv ;layui-layer-lan;layui-layer-rim;layer-window
                shadeClose:false,
                resize: false,
                scrollbar: false,
                maxmin: false,//出现最大化按钮
                content:$('#layer_supplier_window')
            })
        }
    });


    $(".save-produce-btn").on('click',function () {
        var supplierName=formSelects.value('productSupplierId', 'nameStr');
        if(supplierName==''){
            parent.layer.msg('请先选择供应商！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        var qualityResult=$("#qualityResult").val();
        if(qualityResult==''){
            parent.layer.msg('请先选择质检状态！',{icon: 0,time:1500,shade: [0.8, '#393D49']});
            return;
        }
        var selDatas = $relatedTable.bootstrapTable('getSelections');
        if( selDatas.length == 0 ){
            layer.msg('请选择要生成的数据',{icon: 0,shade: [0.8, '#393D49'],time: 1500});
        }else{
            var ids = [];
            var flag=true;
            $.each(selDatas,function(i,d){
                ids.push(d.id);
            });
            ids = ids.join(',');
            if(flag==true) {
                var inde= layer.load(2, { //icon支持传入0-2
                    shade: [0.1, '#fff'], //0.5透明度的灰色背景
                    content: '正在生成验货报告,请稍后...',
                    success: function (layero) {
                        layero.find('.layui-layer-content').css({
                            'padding-top': '39px',
                            'margin-left': '-50px',
                            'width': '300px',
                            'font-color': 'red',
                            'font-size': '20px'
                        });
                    }
                });

                var createPlanNo = [];
                $.each(selDatas,function(i,d){
                    createPlanNo+=d.createPlanNo+',';
                });

                $.ajax({
                    url: "/sea/supply/quality/save",
                    data: {
                        supplierName:supplierName,
                        qualityResult:$("#qualityResult").val(),
                        qualityNumber:$("#qualityNumber").val(),
                        ids:ids,
                        createPlanNo:createPlanNo
                    },
                    type: "post",
                    success: function (data) {
                        if(data.ok){
                            layer.msg("生成成功！",{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                    $relatedTable.bootstrapTable('refresh');
                                }});
                        }else{
                            layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                    layer.closeAll();
                                }});
                        }
                    },
                });
            }
        }
    })
</script>
</body>
</html>
